home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / smashtv.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  7KB  |  278 lines

  1. /*************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. **************************************************************************/
  8. #include "driver.h"
  9. #include "cpu/tms34010/tms34010.h"
  10.  
  11. void wms_stateload(void);
  12. void wms_statesave(void);
  13. void wms_update_partial(int scanline);
  14.  
  15. UINT16 *wms_videoram;
  16. INT32 wms_videoram_size = 0x80000;
  17.  
  18. /* Variables in machine/smashtv.c */
  19. extern UINT8 *wms_cmos_ram;
  20. extern UINT8 wms_autoerase_enable;
  21. extern UINT8 wms_autoerase_reset;
  22. extern UINT32 wms_dma_pal_word;
  23.  
  24. static int last_update_scanline;
  25. static UINT8 update_status;
  26.  
  27. static UINT32 current_offset;
  28. static int current_rowbytes;
  29.  
  30. WRITE_HANDLER( wms_vram_w )
  31. {
  32.     UINT32 tempw,tempwb;
  33.     UINT16 tempwordhi;
  34.     UINT16 tempwordlo;
  35.     UINT16 datalo;
  36.     UINT16 datahi;
  37.     UINT32 mask;
  38.  
  39.     /* first vram data */
  40.     tempwordhi = wms_videoram[offset+1];
  41.     tempwordlo = wms_videoram[offset];
  42.     tempw = (wms_videoram[offset]&0x00ff) + ((wms_videoram[offset+1]&0x00ff)<<8);
  43.     tempwb = COMBINE_WORD(tempw,data);
  44.     datalo = tempwb&0x00ff;
  45.     datahi = (tempwb&0xff00)>>8;
  46.     wms_videoram[offset] = (tempwordlo&0xff00)|datalo;
  47.     wms_videoram[offset+1] = (tempwordhi&0xff00)|datahi;
  48.  
  49.     /* now palette data */
  50.     tempwordhi = wms_videoram[offset+1];
  51.     tempwordlo = wms_videoram[offset];
  52.     mask = (~(((UINT32) data)>>16))|0xffff0000;
  53.     data = ((data&0xffff0000) | wms_dma_pal_word) & mask;
  54.     tempw = (((UINT16) (wms_videoram[offset]&0xff00))>>8) + (wms_videoram[offset+1]&0xff00);
  55.     tempwb = COMBINE_WORD(tempw,data);
  56.     datalo = tempwb&0x00ff;
  57.     datahi = (tempwb&0xff00)>>8;
  58.     wms_videoram[offset] = (tempwordlo&0x00ff)|(datalo<<8);
  59.     wms_videoram[offset+1] = (tempwordhi&0x00ff)|(datahi<<8);
  60. }
  61.  
  62. WRITE_HANDLER( wms_objpalram_w )
  63. {
  64.     UINT32 tempw,tempwb;
  65.     UINT16 tempwordhi;
  66.     UINT16 tempwordlo;
  67.     UINT16 datalo;
  68.     UINT16 datahi;
  69.  
  70.     tempwordhi = wms_videoram[offset+1];
  71.     tempwordlo = wms_videoram[offset];
  72.     tempw = ((wms_videoram[offset]&0xff00)>>8) + (wms_videoram[offset+1]&0xff00);
  73.     tempwb = COMBINE_WORD(tempw,data);
  74.     datalo = tempwb&0x00ff;
  75.     datahi = (tempwb&0xff00)>>8;
  76.     wms_videoram[offset] = (tempwordlo&0x00ff)|(datalo<<8);
  77.     wms_videoram[offset+1] = (tempwordhi&0x00ff)|(datahi<<8);
  78. }
  79.  
  80. READ_HANDLER( wms_vram_r )
  81. {
  82.     return (wms_videoram[offset]&0x00ff) | (wms_videoram[offset+1]<<8);
  83. }
  84.  
  85. READ_HANDLER( wms_objpalram_r )
  86. {
  87.     return (wms_videoram[offset]>>8) | (wms_videoram[offset+1]&0xff00);
  88. }
  89.  
  90. int wms_vh_start(void)
  91. {
  92.     if ((wms_cmos_ram = malloc(0x8000)) == 0)
  93.     {
  94.         logerror("smashtv.c: Couldn't Alloc CMOS RAM\n");
  95.         return 1;
  96.     }
  97.     if ((paletteram = malloc(0x4000)) == 0)
  98.     {
  99.         logerror("smashtv.c: Couldn't Alloc color RAM\n");
  100.         free(wms_cmos_ram);
  101.         return 1;
  102.     }
  103.     if ((wms_videoram = malloc(wms_videoram_size)) == 0)
  104.     {
  105.         logerror("smashtv.c: Couldn't Alloc video RAM\n");
  106.         free(wms_cmos_ram);
  107.         free(paletteram);
  108.         return 1;
  109.     }
  110.     memset(wms_cmos_ram,0,0x8000);
  111.     update_status = 1;
  112.     return 0;
  113. }
  114.  
  115. int wms_t_vh_start(void)
  116. {
  117.     if ((wms_cmos_ram = malloc(0x10000)) == 0)
  118.     {
  119.         logerror("smashtv.c: Couldn't Alloc CMOS RAM\n");
  120.         return 1;
  121.     }
  122.     if ((paletteram = malloc(0x20000)) == 0)
  123.     {
  124.         logerror("smashtv.c: Couldn't Alloc color RAM\n");
  125.         free(wms_cmos_ram);
  126.         return 1;
  127.     }
  128.     if ((wms_videoram = malloc(0x100000)) == 0)
  129.     {
  130.         logerror("smashtv.c: Couldn't Alloc video RAM\n");
  131.         free(wms_cmos_ram);
  132.         free(paletteram);
  133.         return 1;
  134.     }
  135.     memset(wms_cmos_ram,0,0x8000);
  136.     update_status = 1;
  137.     return 0;
  138. }
  139.  
  140. void wms_vh_stop (void)
  141. {
  142.     free(wms_cmos_ram);
  143.     free(wms_videoram);
  144.     free(paletteram);
  145. }
  146.  
  147. void wms_update_partial(int scanline)
  148. {
  149.     struct osd_bitmap *bitmap = Machine->scrbitmap;
  150.     UINT16 *pens = Machine->pens;
  151.     UINT32 offset;
  152.     int v, h, width;
  153.  
  154.     /* don't draw if we're already past the bottom of the screen */
  155.     if (last_update_scanline >= Machine->drv->visible_area.max_y)
  156.         return;
  157.  
  158.     /* don't start before the top of the screen */
  159.     if (last_update_scanline < Machine->drv->visible_area.min_y)
  160.         last_update_scanline = Machine->drv->visible_area.min_y;
  161.  
  162.     /* bail if there's nothing to do */
  163.     if (last_update_scanline > scanline)
  164.         return;
  165.  
  166.     /* determine the base of the videoram */
  167.     offset = (~TMS34010_get_DPYSTRT(0) & 0x1ff0) << 5;
  168.     offset += 512 * (last_update_scanline - Machine->drv->visible_area.min_y);
  169.     offset &= 0x3ffff;
  170.  
  171.     /* determine how many pixels to copy */
  172.     width = Machine->drv->visible_area.max_x;
  173.  
  174.     /* 16-bit refresh case */
  175.     if (bitmap->depth == 16)
  176.     {
  177.         /* loop over rows */
  178.         for (v = last_update_scanline; v <= scanline; v++)
  179.         {
  180.             UINT16 *src = &wms_videoram[offset];
  181.  
  182.             /* handle the refresh */
  183.             if (update_status)
  184.             {
  185.                 UINT16 *dst = (UINT16 *)&bitmap->line[v][0];
  186.                 UINT32 diff = dst - src;
  187.  
  188.                 /* copy one row */
  189.                 for (h = 0; h < width; h++, src++)
  190.                     *(src + diff) = pens[*src];
  191.             }
  192.  
  193.             /* handle the autoerase */
  194.             if (wms_autoerase_enable)
  195.                 memcpy(&wms_videoram[offset], &wms_videoram[510 * 512], width * sizeof(UINT16));
  196.  
  197.             /* point to the next row */
  198.             offset = (offset + 512) & 0x3ffff;
  199.         }
  200.     }
  201.  
  202.     /* 8-bit refresh case */
  203.     else
  204.     {
  205.         /* loop over rows */
  206.         for (v = last_update_scanline; v <= scanline; v++)
  207.         {
  208.             UINT16 *src = &wms_videoram[offset];
  209.  
  210.             /* handle the refresh */
  211.             if (update_status)
  212.             {
  213.                 UINT8 *dst = &bitmap->line[v][0];
  214.  
  215.                 for (h = 0; h < width; h++)
  216.                     *dst++ = pens[*src++];
  217.             }
  218.  
  219.             /* handle the autoerase */
  220.             if (wms_autoerase_enable)
  221.                 memcpy(&wms_videoram[offset], &wms_videoram[510 * 512], width * sizeof(UINT16));
  222.  
  223.             /* point to the next row */
  224.             offset = (offset + 512) & 0x3ffff;
  225.         }
  226.     }
  227.  
  228.     /* remember where we left off */
  229.     last_update_scanline = scanline + 1;
  230. }
  231.  
  232. void wms_display_addr_changed(UINT32 offs, int rowbytes, int scanline)
  233. {
  234.     wms_update_partial(scanline);
  235.     current_offset = offs;
  236.     current_rowbytes = rowbytes;
  237. }
  238.  
  239. void wms_display_interrupt(int scanline)
  240. {
  241.     wms_update_partial(scanline);
  242. }
  243.  
  244. void wms_vh_eof(void)
  245. {
  246.     /* update status == 2: we just updated this frame, don't do any work */
  247.     if (update_status == 2)
  248.         update_status = 1;
  249.  
  250.     /* update status == 1: we've been updating this frame; finish it off */
  251.     else
  252.     {
  253.         wms_update_partial(Machine->drv->visible_area.max_y);
  254.         last_update_scanline = 0;
  255.         if (update_status)
  256.             update_status--;
  257.     }
  258.  
  259.     /* turn off the autoerase (NARC needs this) */
  260.     if (wms_autoerase_reset)
  261.         wms_autoerase_enable = 0;
  262. }
  263.  
  264. void wms_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  265. {
  266.     if (palette_recalc() || full_refresh)  last_update_scanline = 0;
  267.  
  268.     wms_update_partial(Machine->drv->visible_area.max_y);
  269.     last_update_scanline = 0;
  270.     update_status = 2;
  271.  
  272.     //if (keyboard_pressed(KEYCODE_Q)) wms_statesave();
  273.     //if (keyboard_pressed(KEYCODE_W)) wms_stateload();
  274.  
  275.     if (keyboard_pressed(KEYCODE_E)) logerror("log spot\n");
  276.     //if (keyboard_pressed(KEYCODE_R)) logerror("adpcm: okay\n");
  277. }
  278.